package org.micode.demo.db.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.micode.demo.db.domain.dto.SysUserExtDTO;
import org.micode.libs.dao.base.BaseAllDao;

/**
 * 系统用户扩展表，关联型(sys_user_ext) 实体类的Dao
 * <p>
 * @author: wutianbin
 */
@Mapper
public interface SysUserExtDao extends BaseAllDao<SysUserExtDTO> {


    // 非常规sql写这里--- xml 自动生成,不再手动在xml中写sql !!
    @Delete("delete from sys_user_ext" +
            " where user_id = #{userId}")
    @ResultType(Integer.class)
    Integer deleteUserExtByUserId(@Param("userId") Long userId);

    @Select("SELECT * FROM sys_user_ext " +
            "WHERE user_id in (" +
            "   SELECT user_id from sys_user " +
            "   WHERE login_name = #{loginName} " +
            ") limit 1 ")
    @ResultType(SysUserExtDTO.class)
    SysUserExtDTO getByLoginName(@Param("loginName") String loginName);

}
